﻿using CarEdge.Infrastructure.EFCore.MySql;
using CarEdge.Service.Interface;
using Crm.Infrastructure.Tools;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace CarEdge.Admin.Controllers
{
    /// <summary>
    /// 
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
   
    public class BaseController : ControllerBase
    {
        /// <summary>
        /// 
        /// </summary>
        protected readonly I_Login_Service _login_Service;

        /// <summary>
        /// 
        /// </summary>
        /// <param name="login_Service"></param>
        public BaseController(I_Login_Service login_Service)
        {
            System.Threading.Thread.Sleep(500);
            _login_Service = login_Service;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        /// <exception cref="Exception"></exception>
        protected async Task<SysUser> Get_Curr_User()
        {
            string code=this.User.Claims.ToList().First(d=>d.Type==System.Security.Claims.ClaimTypes.Name).Value;

            var user = await _login_Service.Get_User_ByLastCode(code, Config.GetIp());
            if (user == null) {

                throw new Exception("请重新登录");   
            }
            return user;
        }
    }
}
